package com.tianji.promotion.service.impl;

import com.tianji.common.utils.CollUtils;
import com.tianji.promotion.domain.po.Coupon;
import com.tianji.promotion.domain.po.CouponScope;
import com.tianji.promotion.mapper.CouponScopeMapper;
import com.tianji.promotion.service.ICouponScopeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 优惠券作用范围信息 服务实现类
 * </p>
 *
 * @author xjs
 */
@Service
public class CouponScopeServiceImpl extends ServiceImpl<CouponScopeMapper, CouponScope> implements ICouponScopeService {

    @Override
    public void saveCouponScope(Coupon coupon, List<Long> scopes) {
        if(coupon == null || CollUtils.isEmpty(scopes)){
            return;
        }
        List<CouponScope> scopesList = new ArrayList<>(scopes.size());
        for (Long scope : scopes) {
            CouponScope scope1 = new CouponScope();
            scope1.setCouponId(coupon.getId());
            scope1.setType(1);
            scope1.setBizId(scope);
            scopesList.add(scope1);
        }
        this.saveBatch(scopesList);
    }
}
